import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
import plotly.express as px
from geopy.geocoders import Nominatim
import folium
from folium.plugins import HeatMap
from warnings import filterwarnings
filterwarnings('ignore')
res_data = pd.read_csv(r'Enter the absolute path')
res_data.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | approx_cost(for two people) | reviews_list | menu_item | listed_in(type) | listed_in(city) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | Yes | Yes | 4.1/5 | 775 | 080 42297555\r\n+91 9743772233 | Banashankari | Casual Dining | Pasta, Lunch Buffet, Masala Papad, Paneer Laja... | North Indian, Mughlai, Chinese | 800 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | Yes | No | 4.1/5 | 787 | 080 41714161 | Banashankari | Casual Dining | Momos, Lunch Buffet, Chocolate Nirvana, Thai G... | Chinese, North Indian, Thai | 800 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | Yes | No | 3.8/5 | 918 | +91 9663487993 | Banashankari | Cafe, Casual Dining | Churros, Cannelloni, Minestrone Soup, Hot Choc... | Cafe, Mexican, Italian | 800 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | No | No | 3.7/5 | 88 | +91 9620009302 | Banashankari | Quick Bites | Masala Dosa | South Indian, North Indian | 300 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | No | No | 3.8/5 | 166 | +91 8026612447\r\n+91 9901210005 | Basavanagudi | Casual Dining | Panipuri, Gol Gappe | North Indian, Rajasthani | 600 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
res_data.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 51717 entries, 0 to 51716 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 url 51717 non-null object 1 address 51717 non-null object 2 name 51717 non-null object 3 online_order 51717 non-null object 4 book_table 51717 non-null object 5 rate 43942 non-null object 6 votes 51717 non-null int64 7 phone 50509 non-null object 8 location 51696 non-null object 9 rest_type 51490 non-null object 10 dish_liked 23639 non-null object 11 cuisines 51672 non-null object 12 approx_cost(for two people) 51371 non-null object 13 reviews_list 51717 non-null object 14 menu_item 51717 non-null object 15 listed_in(type) 51717 non-null object 16 listed_in(city) 51717 non-null object dtypes: int64(1), object(16) memory usage: 6.7+ MB
Checking null values
d = res_data.isna().sum()
d = d[d>0].sort_values(ascending=False).reset_index()
d.columns = ["Column", 'Null_count']
d['percent_Null'] = round((d['Null_count']/res_data.shape[0])*100, 2)
fig = px.bar(data_frame=d, x = 'Column', y = 'percent_Null', title= 'Num values in the original Data',
labels= {'Column': 'Column Names', 'percent_Null': "Percentage of Null values"})
fig.show()
dish_liked column is having the with most null values, we can't make any recomendation system with this we can drop the colum
res_data.drop(columns=['dish_liked'], inplace=True)
res_data.shape
(51717, 16)
Converting the required columns into float or int
votes, rate, approx_cost(for two people) are of object types, need to convert them to float or int types for further analysis
res_data.rate.unique()
array(['4.1/5', '3.8/5', '3.7/5', '3.6/5', '4.6/5', '4.0/5', '4.2/5',
'3.9/5', '3.1/5', '3.0/5', '3.2/5', '3.3/5', '2.8/5', '4.4/5',
'4.3/5', 'NEW', '2.9/5', '3.5/5', nan, '2.6/5', '3.8 /5', '3.4/5',
'4.5/5', '2.5/5', '2.7/5', '4.7/5', '2.4/5', '2.2/5', '2.3/5',
'3.4 /5', '-', '3.6 /5', '4.8/5', '3.9 /5', '4.2 /5', '4.0 /5',
'4.1 /5', '3.7 /5', '3.1 /5', '2.9 /5', '3.3 /5', '2.8 /5',
'3.5 /5', '2.7 /5', '2.5 /5', '3.2 /5', '2.6 /5', '4.5 /5',
'4.3 /5', '4.4 /5', '4.9/5', '2.1/5', '2.0/5', '1.8/5', '4.6 /5',
'4.9 /5', '3.0 /5', '4.8 /5', '2.3 /5', '4.7 /5', '2.4 /5',
'2.1 /5', '2.2 /5', '2.0 /5', '1.8 /5'], dtype=object)
Performing ffill opetation on rate
res_data.rate.fillna(method='ffill', inplace=True)
res_data.shape
(51717, 16)
Every rating is given out of 5, filtering the numerator and converting it into float
replacing 'new' with 0 and ''-'' with zero
res_data['rate'] = res_data['rate'].apply(lambda x: x.split('/')[0])
res_data.replace('NEW', 0, inplace= True)
res_data.replace('-', 0, inplace=True)
res_data['rate']=res_data['rate'].astype(float)
res_data.rate.unique()
array([4.1, 3.8, 3.7, 3.6, 4.6, 4. , 4.2, 3.9, 3.1, 3. , 3.2, 3.3, 2.8,
4.4, 4.3, 0. , 2.9, 3.5, 2.6, 3.4, 4.5, 2.5, 2.7, 4.7, 2.4, 2.2,
2.3, 4.8, 4.9, 2.1, 2. , 1.8])
res_data['approx_cost(for two people)'].unique()
array(['800', '300', '600', '700', '550', '500', '450', '650', '400',
'900', '200', '750', '150', '850', '100', '1,200', '350', '250',
'950', '1,000', '1,500', '1,300', '199', '80', '1,100', '160',
'1,600', '230', '130', '50', '190', '1,700', nan, '1,400', '180',
'1,350', '2,200', '2,000', '1,800', '1,900', '330', '2,500',
'2,100', '3,000', '2,800', '3,400', '40', '1,250', '3,500',
'4,000', '2,400', '2,600', '120', '1,450', '469', '70', '3,200',
'60', '560', '240', '360', '6,000', '1,050', '2,300', '4,100',
'5,000', '3,700', '1,650', '2,700', '4,500', '140'], dtype=object)
res_data.shape
(51717, 16)
Droping nan values for approx_cost(for two people)
res_data.dropna(subset=['approx_cost(for two people)'],inplace=True)
res_data.shape
(51371, 16)
removing ','
res_data['approx_cost(for two people)'] = res_data['approx_cost(for two people)'].apply(lambda x: x.replace(',',''))
res_data['approx_cost(for two people)']=res_data['approx_cost(for two people)'].astype(float)
res_data.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 51371 entries, 0 to 51716 Data columns (total 16 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 url 51371 non-null object 1 address 51371 non-null object 2 name 51371 non-null object 3 online_order 51371 non-null object 4 book_table 51371 non-null object 5 rate 51371 non-null float64 6 votes 51371 non-null int64 7 phone 50497 non-null object 8 location 51371 non-null object 9 rest_type 51167 non-null object 10 cuisines 51352 non-null object 11 approx_cost(for two people) 51371 non-null float64 12 reviews_list 51371 non-null object 13 menu_item 51371 non-null object 14 listed_in(type) 51371 non-null object 15 listed_in(city) 51371 non-null object dtypes: float64(2), int64(1), object(13) memory usage: 6.7+ MB
res_data.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | cuisines | approx_cost(for two people) | reviews_list | menu_item | listed_in(type) | listed_in(city) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | Yes | Yes | 4.1 | 775 | 080 42297555\r\n+91 9743772233 | Banashankari | Casual Dining | North Indian, Mughlai, Chinese | 800.0 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | Yes | No | 4.1 | 787 | 080 41714161 | Banashankari | Casual Dining | Chinese, North Indian, Thai | 800.0 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | Yes | No | 3.8 | 918 | +91 9663487993 | Banashankari | Cafe, Casual Dining | Cafe, Mexican, Italian | 800.0 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | No | No | 3.7 | 88 | +91 9620009302 | Banashankari | Quick Bites | South Indian, North Indian | 300.0 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | No | No | 3.8 | 166 | +91 8026612447\r\n+91 9901210005 | Basavanagudi | Casual Dining | North Indian, Rajasthani | 600.0 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
Plotting the average ratting for each restaurent
fig = px.bar(data_frame=res_data.groupby('name')['rate'].mean().nlargest(20).reset_index(),
x = 'name', y = 'rate',
labels= {'name': "Restaurent Name", 'rate': "Avegrage rating"},
title='Top 20 restaurents with highest average rating')
fig.update_xaxes(automargin = True)
fig.show()
Famous restaurent types
fig = px.bar(data_frame=res_data['rest_type'].value_counts().nlargest(20).to_frame(name="Restaurent_type_count").reset_index(),
x = 'index',y = 'Restaurent_type_count', width= 900, height= 300,
labels= {'index': 'Restaurent Types','Restaurent_type_count':'Count'}, title='Top 20 Restaurent Types', template='plotly_dark')
fig.show()
Quick Bites dominating all the types and it is twice casual Dining
Alalysing the online order and table bokking option avaliability
dob = res_data[['online_order', 'book_table']].value_counts().reset_index()
dob.columns = ['online_order', 'book_table', 'count']
res_data.online_order.value_counts()
Yes 30444 No 20927 Name: online_order, dtype: int64
fig = px.scatter(data_frame=dob, x = 'online_order', y='book_table', size='count', title='Number of restaurents with online order and book_table option',
template='plotly_white', width=400, height=400)
fig.show()
Restaurents which have online order are most in number
Restaurents which received most number of votes
res_data.groupby('name')[['rate','votes']].max().nlargest(20, columns = ['votes', 'rate']).reset_index()
| name | rate | votes | |
|---|---|---|---|
| 0 | Byg Brewski Brewing Company | 4.9 | 16832 |
| 1 | Toit | 4.7 | 14956 |
| 2 | Truffles | 4.7 | 14726 |
| 3 | AB's - Absolute Barbecues | 4.9 | 12121 |
| 4 | The Black Pearl | 4.8 | 10550 |
| 5 | Big Pitcher | 4.7 | 9300 |
| 6 | Onesta | 4.6 | 9085 |
| 7 | Arbor Brewing Company | 4.5 | 8419 |
| 8 | Empire Restaurant | 4.4 | 8304 |
| 9 | Prost Brew Pub | 4.5 | 7871 |
| 10 | Church Street Social | 4.3 | 7584 |
| 11 | Hoot | 4.2 | 7330 |
| 12 | Barbeque Nation | 4.8 | 7270 |
| 13 | Meghana Foods | 4.5 | 7238 |
| 14 | Flechazo | 4.9 | 7154 |
| 15 | The Hole in the Wall Cafe | 4.6 | 7137 |
| 16 | Biergarten | 4.8 | 7064 |
| 17 | Vapour Pub & Brewery | 4.2 | 6998 |
| 18 | TBC Sky Lounge | 4.7 | 6745 |
| 19 | Chili's American Grill & Bar | 4.8 | 6470 |
fig = px.pie(data_frame=res_data.groupby('name')['votes'].max().nlargest(10).reset_index(),
names= 'name', values= 'votes', hole= 0.3, )
fig.show()
Number of restaurents in given location
res_data.groupby('location')['name'].unique()
location
BTM [Sankranthi Veg Restaurant, Hearts Unlock Cafe...
Banashankari [Jalsa, Spice Elephant, San Churro Cafe, Addhu...
Banaswadi [Cafe Nibras, The Sanctuary, Crunch Pizzas, 9 ...
Bannerghatta Road [Deja Vu Resto Bar, Fattoush, Empire Restauran...
Basavanagudi [Grand Village, Timepass Dinner, Srinathji's C...
...
West Bangalore [FreshMenu, Fit Dish Fetish, Garden City Mobil...
Whitefield [Imperio Cafe, Night Diaries, LocalHost, AB's ...
Wilson Garden [Tree Top, Sahana's (Nati Style), Karavali Kol...
Yelahanka [Prashanth Naati Corner, Red Chillies Curries ...
Yeshwantpur [Chef's Bank, New Agarwal Bhavan, Fishing Boat...
Name: name, Length: 93, dtype: object
num_res = pd.DataFrame()
num_res['location'] = res_data.groupby('location')['name'].unique().index
res_data.groupby('location')['name'].unique().reset_index()['name'].apply(lambda x: len(x))
0 698
1 283
2 199
3 447
4 205
...
88 4
89 819
90 49
91 3
92 69
Name: name, Length: 93, dtype: int64
num_res['Restaurents_counts'] = res_data.groupby('location')['name'].unique().reset_index()['name'].apply(lambda x: len(x))
num_res= num_res.sort_values(by = 'Restaurents_counts', ascending = False)
num_res
| location | Restaurents_counts | |
|---|---|---|
| 89 | Whitefield | 819 |
| 0 | BTM | 698 |
| 19 | Electronic City | 695 |
| 22 | HSR | 681 |
| 56 | Marathahalli | 656 |
| ... | ... | ... |
| 50 | Langford Town | 2 |
| 68 | Rajarajeshwari Nagar | 2 |
| 30 | Jakkur | 1 |
| 64 | Peenya | 1 |
| 39 | Kengeri | 1 |
93 rows × 2 columns
fig = px.bar(data_frame=num_res.head(20), y = 'location',
x = 'Restaurents_counts', orientation='h', title='Top 20 Areas with most Restaurents')
fig.show()
Approx for for 2 people
Distribution of approx cost
res_data['approx_cost(for two people)'].describe()
count 51371.000000 mean 555.431566 std 438.850728 min 40.000000 25% 300.000000 50% 400.000000 75% 650.000000 max 6000.000000 Name: approx_cost(for two people), dtype: float64
fig = px.histogram(data_frame= res_data['approx_cost(for two people)'], marginal='box',
labels= {'value': 'Approx cost for 2 people(Price)'})
fig.show()
Cost vs Rating
fig = px.scatter(data_frame=res_data, x = 'rate', y = 'approx_cost(for two people)',color = 'online_order', template='ygridoff')
fig.show()
Restaurents with more than 4 rating tend to have higher cost and most of the restaurents do not accept online order, restaurents with rating more than 4 is accepting the online orders
res_data['online_order'].value_counts()
Yes 30444 No 20927 Name: online_order, dtype: int64
Difference between prices of restaurents that accept online and do not accept online order
fig = px.violin(data_frame=res_data, x = 'online_order', y = 'approx_cost(for two people)', title='Online order vs cost', template='plotly_dark')
fig.show()
Even though the mean price is same, the restaurents which donot accept the online order is having higher price
Most costly restaurent
res_data[res_data['approx_cost(for two people)'] == res_data['approx_cost(for two people)'].max()].loc[:, 'name'].value_counts()
Le Cirque Signature - The Leela Palace 2 Name: name, dtype: int64
Most cheap restaurent
res_data[res_data['approx_cost(for two people)'] == res_data['approx_cost(for two people)'].min()].loc[:, 'name'].value_counts()
Srinidhi Sagar Food Line 4 Srinidhi Sagar 2 Srinidhi Sagar Deluxe 2 Name: name, dtype: int64
Restaurents with large number of outlets
import plotly.graph_objects as go
fig = go.Figure(data=[go.Table(header=dict(values=['Restaurent_Name', 'Number of outlets']),
cells=dict(values=[res_data.groupby(['name']).agg(['count'])['address'].reset_index().nlargest(20, columns = 'count')['name'].to_list()
, res_data.groupby(['name']).agg(['count'])['address'].reset_index().nlargest(20, columns = 'count')['count'].to_list()]))
])
fig.update_layout(template = 'plotly_dark')
fig.show()
res_data.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | cuisines | approx_cost(for two people) | reviews_list | menu_item | listed_in(type) | listed_in(city) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | Yes | Yes | 4.1 | 775 | 080 42297555\r\n+91 9743772233 | Banashankari | Casual Dining | North Indian, Mughlai, Chinese | 800.0 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | Yes | No | 4.1 | 787 | 080 41714161 | Banashankari | Casual Dining | Chinese, North Indian, Thai | 800.0 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | Yes | No | 3.8 | 918 | +91 9663487993 | Banashankari | Cafe, Casual Dining | Cafe, Mexican, Italian | 800.0 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | No | No | 3.7 | 88 | +91 9620009302 | Banashankari | Quick Bites | South Indian, North Indian | 300.0 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | No | No | 3.8 | 166 | +91 8026612447\r\n+91 9901210005 | Basavanagudi | Casual Dining | North Indian, Rajasthani | 600.0 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
res_data['listed_in(type)'].value_counts().reset_index()
| index | listed_in(type) | |
|---|---|---|
| 0 | Delivery | 25786 |
| 1 | Dine-out | 17664 |
| 2 | Desserts | 3568 |
| 3 | Cafes | 1703 |
| 4 | Drinks & nightlife | 1091 |
| 5 | Buffet | 871 |
| 6 | Pubs and bars | 688 |
Restaurent types
fig = px.bar(data_frame=res_data['listed_in(type)'].value_counts().reset_index(), x = 'index', y = 'listed_in(type)',
labels = {'index': "Restaurent Type", "listed_in(type)": 'Count of Restaurent type'}, title = 'Restaurent types and their count in Banglore')
fig.update_layout(width = 500, height = 300, template = 'seaborn')
fig.show()
Most cooking styles in Banglore for restaurents
res_data.cuisines.value_counts().reset_index()
| index | cuisines | |
|---|---|---|
| 0 | North Indian | 2872 |
| 1 | North Indian, Chinese | 2377 |
| 2 | South Indian | 1822 |
| 3 | Biryani | 915 |
| 4 | Bakery, Desserts | 903 |
| ... | ... | ... |
| 2710 | Fast Food, Chinese, Burger, Hot dogs, Sandwich | 1 |
| 2711 | North Indian, Mughlai, Chinese, Seafood, South... | 1 |
| 2712 | Seafood, Continental, European, Mediterranean | 1 |
| 2713 | Fast Food, Sandwich, Salad, Healthy Food | 1 |
| 2714 | North Indian, Chinese, Arabian, Momos | 1 |
2715 rows × 2 columns
fig = px.treemap(data_frame=res_data.cuisines.value_counts().nlargest(50).reset_index(), path= ['index'], values='cuisines')
fig.update_layout(title = 'Banglore Restaurents cooking styles')
fig.show()
North Indian style of food is mostly dominated in Banglore
Geographical analysis
res_data.location.unique()
array(['Banashankari', 'Basavanagudi', 'Mysore Road', 'Jayanagar',
'Kumaraswamy Layout', 'Rajarajeshwari Nagar', 'Vijay Nagar',
'Uttarahalli', 'JP Nagar', 'South Bangalore', 'City Market',
'Nagarbhavi', 'Bannerghatta Road', 'BTM', 'Kanakapura Road',
'Bommanahalli', 'CV Raman Nagar', 'Electronic City', 'HSR',
'Marathahalli', 'Sarjapur Road', 'Wilson Garden', 'Shanti Nagar',
'Koramangala 5th Block', 'Koramangala 8th Block', 'Richmond Road',
'Koramangala 7th Block', 'Jalahalli', 'Koramangala 4th Block',
'Bellandur', 'Whitefield', 'East Bangalore', 'Old Airport Road',
'Indiranagar', 'Koramangala 1st Block', 'Frazer Town', 'RT Nagar',
'MG Road', 'Brigade Road', 'Lavelle Road', 'Church Street',
'Ulsoor', 'Residency Road', 'Shivajinagar', 'Infantry Road',
'St. Marks Road', 'Cunningham Road', 'Race Course Road',
'Commercial Street', 'Vasanth Nagar', 'HBR Layout', 'Domlur',
'Ejipura', 'Jeevan Bhima Nagar', 'Old Madras Road', 'Malleshwaram',
'Seshadripuram', 'Kammanahalli', 'Koramangala 6th Block',
'Majestic', 'Langford Town', 'Central Bangalore', 'Sanjay Nagar',
'Brookefield', 'ITPL Main Road, Whitefield',
'Varthur Main Road, Whitefield', 'KR Puram',
'Koramangala 2nd Block', 'Koramangala 3rd Block', 'Koramangala',
'Hosur Road', 'Rajajinagar', 'Banaswadi', 'North Bangalore',
'Nagawara', 'Hennur', 'Kalyan Nagar', 'New BEL Road', 'Jakkur',
'Rammurthy Nagar', 'Thippasandra', 'Kaggadasapura', 'Hebbal',
'Kengeri', 'Sankey Road', 'Sadashiv Nagar', 'Basaveshwara Nagar',
'Yeshwantpur', 'West Bangalore', 'Magadi Road', 'Yelahanka',
'Sahakara Nagar', 'Peenya'], dtype=object)
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="app")
loc = geolocator.geocode('CV Raman Nagar')
loc
Location(CV Raman, Wyra Road, Kaviraj Nagar, Khammam, Khammam_Urban mandal, Khammam, Telangana, 507002, India, (17.2510682, 80.1651978, 0.0))
It is giving us the data of Telengana state
loc = geolocator.geocode('CV Raman Nagar, Banglore')
print(loc)
None
loc = geolocator.geocode('Banashankari, Bangalore')
print(loc)
Banashankari, Kanakapura Road, Kadirenahalli, Banashankari Temple ward, South Zone, Bengaluru, Bangalore South, Bangalore Urban, Karnataka, 560070", India
loc = geolocator.geocode('Kalyan Nagar, Hyderabad')
print(loc)
Kalyan Nagar, Ward 101 Erragadda, Greater Hyderabad Municipal Corporation Central Zone, Hyderabad, Balanagar mandal, Medchal–Malkajgiri, Telangana, 500018, India
Appending Bangalore at the end for location column
location_df = pd.DataFrame({"Location": res_data['location'].unique()})
location_df.head()
| Location | |
|---|---|
| 0 | Banashankari |
| 1 | Basavanagudi |
| 2 | Mysore Road |
| 3 | Jayanagar |
| 4 | Kumaraswamy Layout |
location_df['Location_State'] = location_df['Location'] + ", "+ "Bangalore"
location_df.head()
| Location | Location_State | |
|---|---|---|
| 0 | Banashankari | Banashankari, Bangalore |
| 1 | Basavanagudi | Basavanagudi, Bangalore |
| 2 | Mysore Road | Mysore Road, Bangalore |
| 3 | Jayanagar | Jayanagar, Bangalore |
| 4 | Kumaraswamy Layout | Kumaraswamy Layout, Bangalore |
def get_lat_long(x):
"""
Return the latitude and longitude for a given location
x: input str, takes the location as an input
"""
loc = geolocator.geocode(x)
if loc is None:
return np.nan
else:
return (loc.latitude, loc.longitude)
location_df['Latitude_Longitude'] = location_df['Location_State'].apply(get_lat_long)
location_df.head()
| Location | Location_State | Latitude_Longitude | |
|---|---|---|---|
| 0 | Banashankari | Banashankari, Bangalore | (12.9152208, 77.573598) |
| 1 | Basavanagudi | Basavanagudi, Bangalore | (12.9417261, 77.5755021) |
| 2 | Mysore Road | Mysore Road, Bangalore | (12.9569278, 77.5497675) |
| 3 | Jayanagar | Jayanagar, Bangalore | (12.9292731, 77.5824229) |
| 4 | Kumaraswamy Layout | Kumaraswamy Layout, Bangalore | (12.9081487, 77.5553179) |
location_df.isna().sum()
Location 0 Location_State 0 Latitude_Longitude 1 dtype: int64
location_df[location_df.isna().any(axis=1)]
| Location | Location_State | Latitude_Longitude | |
|---|---|---|---|
| 79 | Rammurthy Nagar | Rammurthy Nagar, Bangalore | NaN |
loc = geolocator.geocode('Rammurthy Nagar, Bangalore')
print(loc)
None
Speperating latitude and longitude columns
out = location_df['Latitude_Longitude'].apply(pd.Series)
out.columns = ['Latitude', 'Longitude']
location_df['Latitude'] = out['Latitude']
location_df['Longitude'] = out['Longitude']
location_df
| Location | Location_State | Latitude_Longitude | Latitude | Longitude | |
|---|---|---|---|---|---|
| 0 | Banashankari | Banashankari, Bangalore | (12.9152208, 77.573598) | 12.915221 | 77.573598 |
| 1 | Basavanagudi | Basavanagudi, Bangalore | (12.9417261, 77.5755021) | 12.941726 | 77.575502 |
| 2 | Mysore Road | Mysore Road, Bangalore | (12.9569278, 77.5497675) | 12.956928 | 77.549768 |
| 3 | Jayanagar | Jayanagar, Bangalore | (12.9292731, 77.5824229) | 12.929273 | 77.582423 |
| 4 | Kumaraswamy Layout | Kumaraswamy Layout, Bangalore | (12.9081487, 77.5553179) | 12.908149 | 77.555318 |
| ... | ... | ... | ... | ... | ... |
| 88 | West Bangalore | West Bangalore, Bangalore | (12.9848519, 77.5400626) | 12.984852 | 77.540063 |
| 89 | Magadi Road | Magadi Road, Bangalore | (12.9882076, 77.5113613) | 12.988208 | 77.511361 |
| 90 | Yelahanka | Yelahanka, Bangalore | (13.1006982, 77.5963454) | 13.100698 | 77.596345 |
| 91 | Sahakara Nagar | Sahakara Nagar, Bangalore | (13.0621474, 77.58006135480495) | 13.062147 | 77.580061 |
| 92 | Peenya | Peenya, Bangalore | (13.0329419, 77.5273253) | 13.032942 | 77.527325 |
93 rows × 5 columns
locations = res_data['location'].value_counts().reset_index()
locations.columns = ['Location', 'Count']
locations
| Location | Count | |
|---|---|---|
| 0 | BTM | 5098 |
| 1 | HSR | 2508 |
| 2 | Koramangala 5th Block | 2481 |
| 3 | JP Nagar | 2230 |
| 4 | Whitefield | 2133 |
| ... | ... | ... |
| 88 | West Bangalore | 6 |
| 89 | Yelahanka | 5 |
| 90 | Jakkur | 3 |
| 91 | Rajarajeshwari Nagar | 2 |
| 92 | Peenya | 1 |
93 rows × 2 columns
location_df = locations.merge(location_df, on = 'Location', how = 'left').dropna()
location_df
| Location | Count | Location_State | Latitude_Longitude | Latitude | Longitude | |
|---|---|---|---|---|---|---|
| 0 | BTM | 5098 | BTM, Bangalore | (12.911275849999999, 77.60456543431182) | 12.911276 | 77.604565 |
| 1 | HSR | 2508 | HSR, Bangalore | (12.9116225, 77.6388622) | 12.911623 | 77.638862 |
| 2 | Koramangala 5th Block | 2481 | Koramangala 5th Block, Bangalore | (12.9348429, 77.6189768) | 12.934843 | 77.618977 |
| 3 | JP Nagar | 2230 | JP Nagar, Bangalore | (12.9072515, 77.5782713) | 12.907251 | 77.578271 |
| 4 | Whitefield | 2133 | Whitefield, Bangalore | (12.9696365, 77.7497448) | 12.969637 | 77.749745 |
| ... | ... | ... | ... | ... | ... | ... |
| 88 | West Bangalore | 6 | West Bangalore, Bangalore | (12.9848519, 77.5400626) | 12.984852 | 77.540063 |
| 89 | Yelahanka | 5 | Yelahanka, Bangalore | (13.1006982, 77.5963454) | 13.100698 | 77.596345 |
| 90 | Jakkur | 3 | Jakkur, Bangalore | (13.0784743, 77.6068938) | 13.078474 | 77.606894 |
| 91 | Rajarajeshwari Nagar | 2 | Rajarajeshwari Nagar, Bangalore | (12.9274413, 77.5155224) | 12.927441 | 77.515522 |
| 92 | Peenya | 1 | Peenya, Bangalore | (13.0329419, 77.5273253) | 13.032942 | 77.527325 |
92 rows × 6 columns
constructing Base map for Banglorre location
loc = geolocator.geocode('Bangalore, Karnataka')
print(loc.latitude, loc.longitude)
12.9767936 77.590082
import folium
basemap = folium.Map(location= [12.9767936, 77.590082])
from branca.element import Figure
fig1=Figure(width=750,height=300)
basemap = folium.Map(location= [12.9767936, 77.590082])
fig1.add_child(basemap)
folium.TileLayer('Stamen Terrain').add_to(basemap)
folium.TileLayer('Stamen Toner').add_to(basemap)
folium.TileLayer('Stamen Water Color').add_to(basemap)
folium.TileLayer('cartodbpositron').add_to(basemap)
folium.TileLayer('cartodbdark_matter').add_to(basemap)
folium.LayerControl().add_to(basemap)
folium.Marker(location=[12.9767936, 77.590082],tooltip='Bangalore, Karnataka').add_to(basemap)
basemap
def get_basemap(default_loc = [12.9767936, 77.590082], width = 750, height = 500, tooltip = "Bangalore", zoom = 12 ):
"""
This will genetrate the Base map with default customization
"""
fig1=Figure(width=width,height=height)
basemap = folium.Map(location= default_loc, zoom_start=zoom)
fig1.add_child(basemap)
folium.Marker(location=default_loc, tooltip=f'{tooltip}').add_to(basemap)
return basemap
loc_base = get_basemap()
loc_base
markers = location_df[['Latitude', 'Longitude', 'Location']]
len(markers)
92
for i in range(0,len(markers)):
folium.Marker(
location=[markers.iloc[i]['Latitude'], markers.iloc[i]['Longitude']],
popup=markers.iloc[i]['Location'],
).add_to(loc_base)
Restaurents Locations in Bangalore
loc_base
Finding locations of Cafe Coffee Day
cafe_cofee_day = res_data[res_data.name == 'Cafe Coffee Day']
cafe_cofee_day["Location_state"] = cafe_cofee_day['location'] + ", "+"Bangalore"
cafe_cofee_day = cafe_cofee_day[['name','location', 'Location_state']]
cafe_cofee_day.drop_duplicates(subset='location', inplace=True, keep = 'first')
cafe_cofee_day.reset_index(drop = True, inplace = True)
cafe_cofee_day
| name | location | Location_state | |
|---|---|---|---|
| 0 | Cafe Coffee Day | Banashankari | Banashankari, Bangalore |
| 1 | Cafe Coffee Day | Jayanagar | Jayanagar, Bangalore |
| 2 | Cafe Coffee Day | Bannerghatta Road | Bannerghatta Road, Bangalore |
| 3 | Cafe Coffee Day | Basavanagudi | Basavanagudi, Bangalore |
| 4 | Cafe Coffee Day | Wilson Garden | Wilson Garden, Bangalore |
| 5 | Cafe Coffee Day | Bellandur | Bellandur, Bangalore |
| 6 | Cafe Coffee Day | Sarjapur Road | Sarjapur Road, Bangalore |
| 7 | Cafe Coffee Day | Brigade Road | Brigade Road, Bangalore |
| 8 | Cafe Coffee Day | Race Course Road | Race Course Road, Bangalore |
| 9 | Cafe Coffee Day | Brookefield | Brookefield, Bangalore |
| 10 | Cafe Coffee Day | Marathahalli | Marathahalli, Bangalore |
| 11 | Cafe Coffee Day | BTM | BTM, Bangalore |
| 12 | Cafe Coffee Day | Lavelle Road | Lavelle Road, Bangalore |
| 13 | Cafe Coffee Day | Electronic City | Electronic City, Bangalore |
| 14 | Cafe Coffee Day | Frazer Town | Frazer Town, Bangalore |
| 15 | Cafe Coffee Day | HSR | HSR, Bangalore |
| 16 | Cafe Coffee Day | Indiranagar | Indiranagar, Bangalore |
| 17 | Cafe Coffee Day | JP Nagar | JP Nagar, Bangalore |
| 18 | Cafe Coffee Day | Kalyan Nagar | Kalyan Nagar, Bangalore |
| 19 | Cafe Coffee Day | Nagawara | Nagawara, Bangalore |
| 20 | Cafe Coffee Day | Kammanahalli | Kammanahalli, Bangalore |
| 21 | Cafe Coffee Day | Koramangala 5th Block | Koramangala 5th Block, Bangalore |
| 22 | Cafe Coffee Day | Koramangala 6th Block | Koramangala 6th Block, Bangalore |
| 23 | Cafe Coffee Day | Koramangala 7th Block | Koramangala 7th Block, Bangalore |
| 24 | Cafe Coffee Day | Malleshwaram | Malleshwaram, Bangalore |
| 25 | Cafe Coffee Day | New BEL Road | New BEL Road, Bangalore |
| 26 | Cafe Coffee Day | MG Road | MG Road, Bangalore |
| 27 | Cafe Coffee Day | Old Airport Road | Old Airport Road, Bangalore |
| 28 | Cafe Coffee Day | Rajajinagar | Rajajinagar, Bangalore |
| 29 | Cafe Coffee Day | Vijay Nagar | Vijay Nagar, Bangalore |
| 30 | Cafe Coffee Day | Basaveshwara Nagar | Basaveshwara Nagar, Bangalore |
| 31 | Cafe Coffee Day | Residency Road | Residency Road, Bangalore |
| 32 | Cafe Coffee Day | Seshadripuram | Seshadripuram, Bangalore |
| 33 | Cafe Coffee Day | Whitefield | Whitefield, Bangalore |
cafe_cofee_day['Latitude_Longitude'] = cafe_cofee_day['Location_state'].apply(get_lat_long)
cafe_cofee_day.isna().sum()
name 0 location 0 Location_state 0 Latitude_Longitude 0 dtype: int64
out = cafe_cofee_day['Latitude_Longitude'].apply(pd.Series)
out.columns = ['Latitude', 'Longitude']
cafe_cofee_day['Latitude'] = out['Latitude']
cafe_cofee_day['Longitude'] = out['Longitude']
cafe_cofee_day
| name | location | Location_state | Latitude_Longitude | Latitude | Longitude | |
|---|---|---|---|---|---|---|
| 0 | Cafe Coffee Day | Banashankari | Banashankari, Bangalore | (12.9152208, 77.573598) | 12.915221 | 77.573598 |
| 1 | Cafe Coffee Day | Jayanagar | Jayanagar, Bangalore | (12.9292731, 77.5824229) | 12.929273 | 77.582423 |
| 2 | Cafe Coffee Day | Bannerghatta Road | Bannerghatta Road, Bangalore | (12.8545439, 77.5886892) | 12.854544 | 77.588689 |
| 3 | Cafe Coffee Day | Basavanagudi | Basavanagudi, Bangalore | (12.9417261, 77.5755021) | 12.941726 | 77.575502 |
| 4 | Cafe Coffee Day | Wilson Garden | Wilson Garden, Bangalore | (12.9489339, 77.5968273) | 12.948934 | 77.596827 |
| 5 | Cafe Coffee Day | Bellandur | Bellandur, Bangalore | (12.93103185, 77.6782471) | 12.931032 | 77.678247 |
| 6 | Cafe Coffee Day | Sarjapur Road | Sarjapur Road, Bangalore | (12.924299, 77.6517653) | 12.924299 | 77.651765 |
| 7 | Cafe Coffee Day | Brigade Road | Brigade Road, Bangalore | (12.9736132, 77.6074716) | 12.973613 | 77.607472 |
| 8 | Cafe Coffee Day | Race Course Road | Race Course Road, Bangalore | (12.9838271, 77.5853279) | 12.983827 | 77.585328 |
| 9 | Cafe Coffee Day | Brookefield | Brookefield, Bangalore | (12.9668213, 77.7168891) | 12.966821 | 77.716889 |
| 10 | Cafe Coffee Day | Marathahalli | Marathahalli, Bangalore | (12.9552572, 77.6984163) | 12.955257 | 77.698416 |
| 11 | Cafe Coffee Day | BTM | BTM, Bangalore | (12.911275849999999, 77.60456543431182) | 12.911276 | 77.604565 |
| 12 | Cafe Coffee Day | Lavelle Road | Lavelle Road, Bangalore | (12.9683054, 77.5964883) | 12.968305 | 77.596488 |
| 13 | Cafe Coffee Day | Electronic City | Electronic City, Bangalore | (12.848759900000001, 77.64825295827616) | 12.848760 | 77.648253 |
| 14 | Cafe Coffee Day | Frazer Town | Frazer Town, Bangalore | (12.996845, 77.6130165) | 12.996845 | 77.613017 |
| 15 | Cafe Coffee Day | HSR | HSR, Bangalore | (12.9116225, 77.6388622) | 12.911623 | 77.638862 |
| 16 | Cafe Coffee Day | Indiranagar | Indiranagar, Bangalore | (12.9732913, 77.6404672) | 12.973291 | 77.640467 |
| 17 | Cafe Coffee Day | JP Nagar | JP Nagar, Bangalore | (12.9072515, 77.5782713) | 12.907251 | 77.578271 |
| 18 | Cafe Coffee Day | Kalyan Nagar | Kalyan Nagar, Bangalore | (13.0221416, 77.6403368) | 13.022142 | 77.640337 |
| 19 | Cafe Coffee Day | Nagawara | Nagawara, Bangalore | (13.0412234, 77.6249525) | 13.041223 | 77.624953 |
| 20 | Cafe Coffee Day | Kammanahalli | Kammanahalli, Bangalore | (13.0093455, 77.6377094) | 13.009346 | 77.637709 |
| 21 | Cafe Coffee Day | Koramangala 5th Block | Koramangala 5th Block, Bangalore | (12.9348429, 77.6189768) | 12.934843 | 77.618977 |
| 22 | Cafe Coffee Day | Koramangala 6th Block | Koramangala 6th Block, Bangalore | (12.9390255, 77.6238477) | 12.939025 | 77.623848 |
| 23 | Cafe Coffee Day | Koramangala 7th Block | Koramangala 7th Block, Bangalore | (12.9364846, 77.6134783) | 12.936485 | 77.613478 |
| 24 | Cafe Coffee Day | Malleshwaram | Malleshwaram, Bangalore | (13.0027353, 77.5703253) | 13.002735 | 77.570325 |
| 25 | Cafe Coffee Day | New BEL Road | New BEL Road, Bangalore | (13.0290931, 77.5710622) | 13.029093 | 77.571062 |
| 26 | Cafe Coffee Day | MG Road | MG Road, Bangalore | (12.9755264, 77.6067902) | 12.975526 | 77.606790 |
| 27 | Cafe Coffee Day | Old Airport Road | Old Airport Road, Bangalore | (12.9593577, 77.6614182) | 12.959358 | 77.661418 |
| 28 | Cafe Coffee Day | Rajajinagar | Rajajinagar, Bangalore | (12.9882338, 77.554883) | 12.988234 | 77.554883 |
| 29 | Cafe Coffee Day | Vijay Nagar | Vijay Nagar, Bangalore | (12.96595445, 77.61253320881664) | 12.965954 | 77.612533 |
| 30 | Cafe Coffee Day | Basaveshwara Nagar | Basaveshwara Nagar, Bangalore | (12.9932236, 77.5391579) | 12.993224 | 77.539158 |
| 31 | Cafe Coffee Day | Residency Road | Residency Road, Bangalore | (13.052791, 77.6203393) | 13.052791 | 77.620339 |
| 32 | Cafe Coffee Day | Seshadripuram | Seshadripuram, Bangalore | (12.9931876, 77.5753419) | 12.993188 | 77.575342 |
| 33 | Cafe Coffee Day | Whitefield | Whitefield, Bangalore | (12.9696365, 77.7497448) | 12.969637 | 77.749745 |
cafe_cofee_day_base = get_basemap()
cafe_cofee_day_base
for i in range(0,len(cafe_cofee_day)):
folium.Marker(
location=[cafe_cofee_day.iloc[i]['Latitude'], cafe_cofee_day.iloc[i]['Longitude']],
popup=markers.iloc[i]['Location'],
).add_to(cafe_cofee_day_base)
All the locations of cafe Cofee Day
cafe_cofee_day_base
Same applies for all the other locations, create a function to do this
Heat map for the locations
Heat map for count of restaurents in the location
from folium.plugins import HeatMap
all_loc_base_heat = get_basemap()
HeatMap(location_df[['Latitude','Longitude','Count']].values.tolist(),zoom=20,radius=15).add_to(all_loc_base_heat)
<folium.plugins.heat_map.HeatMap at 0x235a022a748>
all_loc_base_heat
Restaurents tents to be concentrated in the central banglore, By refering to this we can understant with area is most suitable for new restaurents